package com.goblin.model.film.repository;

import javax.persistence.EntityManager;

import com.goblin.common.response.PageHelper;
import com.goblin.common.response.Paged;
import com.goblin.model.base.BaseRepositoryImpl;
import com.goblin.model.film.po.Film;
import com.goblin.model.film.po.QFilm;
import com.querydsl.core.QueryResults;
import com.querydsl.jpa.JPQLQuery;

public class FilmRepositoryImpl extends BaseRepositoryImpl<Film, Integer>
		implements FilmRepositoryCustom {

	public FilmRepositoryImpl(EntityManager entityManager) {
		super(Film.class, entityManager);
	}

	@Override
	public Paged<Film> paged(PageHelper pageable) {
		JPQLQuery<Film> query = this.jpaQueryFactory.selectFrom(QFilm.film)
				.where(QFilm.film.deleteTime.isNull()).orderBy(QFilm.film.grade.desc());
		query = (JPQLQuery<Film>) getQuerydsl(pageable, query);
		QueryResults<Film> results = query.fetchResults();
		return new Paged<Film>(results.getTotal(), results.getResults());
	}
}
